package com.aosgame;

import android.graphics.Bitmap;
import android.graphics.Rect;

import com.androidgame.fx.Graphics;

public class GameButton {

	private Bitmap	onImage;
	private Bitmap	offImage;
	private Rect	rect;
	private boolean	touched;
	
	public GameButton(Bitmap onImage, Bitmap offImage, int left, int top) {
		this.onImage = onImage;
		this.offImage = offImage;
		rect = new Rect(left, top, left + onImage.getWidth(), top + onImage.getHeight());
		touched = false;
	}
	
	public boolean touchDown(int x, int y) {
		if(rect.contains(x, y)) {
			touched = true;
		}
		return false;
	}
	
	public boolean touchDragged(int x, int y) {
		if(rect.contains(x, y)) {
			touched = true;
		} else {
			touched = false;
		}
		return false;
	}
	
	public boolean touchUp(int x, int y) {
		if(rect.contains(x, y)) {
			touched = false;
			return true;
		}
		return false;
	}
	
	public void present(Graphics g) {
		if(touched) {
			g.drawBitmap(offImage, rect.left, rect.top);
		} else {
			g.drawBitmap(onImage, rect.left, rect.top);
		}
	}
}
